<template>
	<view>
		<view>
			<image src="https://shopimges.oss-cn-hangzhou.aliyuncs.com/mimi/ben1.jpg" mode="aspectFill" class="image">
			</image>
		</view>
		<view class="bojing">
			<view>
				<u-grid :border="false" col="4">
					<u-grid-item v-for="(listItem,listIndex) in lists" :key="listIndex" @click="jon(listItem.lx)"
						customStyle="padding-top: 10px; padding-bottom: 10px">
						<u-icon :customStyle="{paddingTop:20+'rpx'}" :name="listItem.name" :size="30"></u-icon>
						<text class="grid-text">{{listItem.title}}</text>
					</u-grid-item>
				</u-grid>
			</view>
			
			<view class="bode_y" v-for="(item,index) in listData" :key="index">
				<image :src="item.ioc" mode="widthFix" class="huodong" @click="yian({item})"></image>
			</view>
			 <view class="ad-view">
			      <ad adpid="1111111111" @load="onload" @close="onclose" @error="onerror"></ad>
			    </view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listData:[],
				lists: [{
						name: 'https://shopimges.oss-cn-hangzhou.aliyuncs.com/mimi/hua.png',
						title: '话题',
						lx:0
					},
					{
						name: 'https://shopimges.oss-cn-hangzhou.aliyuncs.com/mimi/faxian.png',
						title: '发现',
						lx:1
					},
					{
						name: 'https://shopimges.oss-cn-hangzhou.aliyuncs.com/mimi/liwu.png',
						title: '礼品',
						lx:2
					},
					{
						name: 'https://shopimges.oss-cn-hangzhou.aliyuncs.com/mimi/xiehou.png',
						title: '邂逅',
						lx:3
					}
				]
			}
		},
		onLoad() {
			this.getlist();
		},
		onShow() {
			
		},
		methods:{
			getlist(){
				uni.$u.http.post('Chat/homeList',{})
				 .then(res => {
					// console.log(res)
					this.listData=res.data
				})
			},
			jon(e){
				if(e==0){
					uni.$u.route({
						url: "/pages/garden/list"
					})
				}else if(e==1){
					uni.$u.route({
						url: "/pages/mimi/list"
					})
				}else{
					uni.$u.toast('未开通')
				}
				console.log(e)
			},
			yian(itme){
				const userInfo = uni.getStorageSync('userInfo');
				if (userInfo) {
					uni.$u.route({
						url: "/pages/garden/details?id="+itme.item.id
					})
						
				}else{
					uni.$u.toast('未登录')
				}
				
				
			},
					        ///方法名 需要有个按钮来执行该方法
			             adLoad: function(key) {
							var t = this;
							uni.showLoading({
								title: '请稍等'
							})
									if (wx.createRewardedVideoAd) {
										videoAd = wx.createRewardedVideoAd({
											adUnitId: "1111111111" //你的广告key
			 
										})
										if (videoAd) {
											videoAd.show().catch(err => {
												// 失败重试
												// console.log("广告拉去失败")
												videoAd.load().then(() => videoAd.show())
											})
										}
										videoAd.onError(err => {
											console.log(err)
										})
										videoAd.onClose((status) => {
											if (status && status.isEnded || status === undefined) {
												//这里写广告播放完成后的事件
												uni.showToast({
													title: '获取自定义路径权限成功！',
													icon: "none",
													duration: 2000
												})
												return;
											} else {}
										})
									} else {
										console.log("创建失败")
									}
								},
								complete() {
									setTimeout(() => {
										uni.hideLoading()
									}, 2000)
			 
						},
		}
	}
</script>

<style>
	.image {
		width: 100%;
		height: 55vh;
	}

	.bojing {
		background-color: #fff;
		padding: 20rpx;
		border-top-left-radius: 40rpx;
		border-top-right-radius: 40rpx;
		margin-top: -40rpx;
		position: relative;
		width: 94.8vw;
	}

	.grid-text {
		font-size: 24rpx;
		color: #545252;
	}
	.bode_y{
		padding: 10rpx 20rpx;
	}
	.huodong{
		width: 100%;
		border-radius: 15rpx;
		box-shadow: 10rpx 10rpx 20rpx #bababa;
	}
</style>
